package com.example.myapplication.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.old.GameFragment;
import com.example.myapplication.R;
import com.example.myapplication.adapter.viewPagerAdapter.VideoAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class VideoFragment extends Fragment {

    private ViewPager view_page;
    private TabLayout tab_layout;
    private View view;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_blank, container, false);
        init();
        return view;
    }

    private void init() {
            view_page = view.findViewById(R.id.recyclerView1);
            tab_layout = view.findViewById(R.id.tab_layout);
            List<Fragment> fragmentList = new ArrayList<>();
            fragmentList.add(new VideoRecommendFragment());
            VideoAdapter adapter = new VideoAdapter(getChildFragmentManager(),fragmentList);
            view_page.setAdapter(adapter);
            //设置tablayout字体选中变大加粗
            tab_layout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                @Override
                public void onTabSelected(TabLayout.Tab tab) {
                    TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.tab_item_text,null);
                    textView.setText(tab.getText());
                    tab.setCustomView(textView);
                }
                @Override
                public void onTabUnselected(TabLayout.Tab tab) {
                    tab.setCustomView(null);
                }

                @Override
                public void onTabReselected(TabLayout.Tab tab) {

                }
            });
            tab_layout.setupWithViewPager(view_page);
    }
}
